<template>
  <div>
    <h1>英皇教育幼儿园使用平台</h1>
    <table border="1" cellspacing="1" align="center">
      <tr>
        <td>年级</td>
        <td colspan="3">课程</td>
      </tr>
      <tr v-for="i in cla">
        <td>{{ i.name }}</td>
        <td v-for="j in i.grade">{{ j.name }}</td>
      </tr>
    </table>
    <div>
      <h1>登录</h1>
      <p>名字：<input type="text" v-model="form.name"></p>
      <p>账号：<input type="text" v-model="form.username"></p>
      <p>密码：<input type="text" v-model="form.password"></p>
      <p>班级:
        <select name="" id="" v-model="form.grade">
          <option :value="i.id" v-for="i in cla">{{ i.name }}</option>
        </select>
      </p>
      <button @click="post_user">登录</button>
    </div>

  </div>

</template>

<script>
export default {
  name: "lesson",
  data() {
    return {
      cla: [],
      form:{}
    }
  },
  methods: {
    get_less() {
      this.$axios.get('users/GradeAPI/')
        .then(res => {
          this.cla = res.data.list
        })
    },
    post_user(){
      this.$axios.post('users/GradeAPI/',this.form)
      .then(res=>{
        if(res.data.code==200){
          alert('ok')
          localStorage.setItem('userid',res.data.userid)
          this.$router.push({path:'/firends'})
        }else {
          alert('no')
        }
      })
    }
  },
  mounted() {
    this.get_less()
  }
}
</script>

<style scoped>

</style>
